package com.mallcloud.mall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.common.excel.annotation.ResponseExcel;
import com.mallcloud.mall.product.api.entity.ShopDetailModel;
import com.mallcloud.mall.product.service.ShopDetailService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "店铺详情管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/product/shopDetail")
public class ShopDetailController {
    private final ShopDetailService shopDetailService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('product_shopdetail_view')")
    public R<IPage<ShopDetailModel>> page(Page page, ShopDetailModel dto) {
        return R.ok(shopDetailService.page(page, Wrappers.query(dto)));
    }

    @ApiOperation("列表查询")
    @GetMapping("/list")
    @PreAuthorize("@pms.hasPermission('product_shopdetail_view')")
    public R<List<ShopDetailModel>> list(ShopDetailModel dto) {
        return R.ok(shopDetailService.list(Wrappers.query(dto)));
    }

    @ApiOperation("通过id查询")
    @GetMapping("/getInfo")
    @PreAuthorize("@pms.hasPermission('product_shopdetail_view')")
    public R<ShopDetailModel> getInfo(ShopDetailModel dto) {
        return R.ok(shopDetailService.getById(dto.getShopId()));
    }

    @ApiOperation("新增")
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('product_shopdetail_add')")
    public R<Boolean> save(@RequestBody ShopDetailModel dto) {
        return R.ok(shopDetailService.save(dto));
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    @PreAuthorize("@pms.hasPermission('product_shopdetail_edit')")
    public R<Boolean> updateById(@RequestBody ShopDetailModel dto) {
        return R.ok(shopDetailService.updateById(dto));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{shopId}")
    @PreAuthorize("@pms.hasPermission('product_shopdetail_del')")
    public R<Boolean> removeById(@PathVariable Integer shopId) {
        return R.ok(shopDetailService.removeById(shopId));
    }

    @ApiOperation("批量删除店铺详情")
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('product_shopdetail_del')")
    public R<Boolean> removeByIds(@RequestBody List<Long> shopIds) {
        return R.ok(shopDetailService.removeByIds(shopIds));
    }

    @ApiOperation("导出")
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('product_shopdetail_export')")
    public List<ShopDetailModel> export(ShopDetailModel shodetail) {
        return shopDetailService.list(Wrappers.query(shodetail));
    }
}
